package com.xzgj.fmmall.config;

import com.xzgj.fmmall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration//加载当前的拦截器并进行注册
/**
 * 处理器拦截器的注册
 */
public class LoginInterceptorConfig implements WebMvcConfigurer {

    /**
     * 配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //创建自定义的拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();
        //配置白名单，存放在一个List集合
        List<String> patterns = new ArrayList<>();
        patterns.add("/**");
//        完成拦截器的注册
//        addPathPatterns:添加路径参数,表示要拦截的url是什么
//        excludePathPatterns:除了***的url List集合
        registry.addInterceptor(interceptor).addPathPatterns("/**")
        .excludePathPatterns(patterns);
    }
}
